//
//  ZGLBankCardInfoController.m
//  ZeegingLottery
//
//  Created by 李曌 on 2018/8/24.
//  Copyright © 2018年 蒂埃里. All rights reserved.
//

#import "ZGLBankCardInfoController.h"
#import "ZGLExtractCashController.h"


@interface ZGLBankCardInfoController ()<UIGestureRecognizerDelegate>

@property (weak, nonatomic) IBOutlet UITextField *bankCardTF;

@property (weak, nonatomic) IBOutlet UITextField *bankTF;

@property (weak, nonatomic) IBOutlet UITextField *bankLocation;

@property (weak, nonatomic) IBOutlet UILabel *realName;

@end

@implementation ZGLBankCardInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"绑定提现银行卡";
    self.realName.text = self.realNameString;
    [self setLeftBackButtonWith:@"取消" Image:nil];
    
//    WS(weakself)
//    dispatch_async(dispatch_get_main_queue(), ^{
//
//        [weakSelf getExtractCashInfo];
//    });
}

//////获取提现信息
//- (void)getExtractCashInfo
//{
//    WS(weakself)
//    [sZGLHTTPRequestManager getBankCardInfoWithSuccess:^(id responsedata) {
//
//        
//    } Fail:^(ZGLRespondStatusCode bef_status, NSString *bef_message, NSError *error) {
//        
//        DLog(@"获取提现信息失败");
//    }];
//}

-(void)viewDidAppear:(BOOL)animated{
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer
                                      *)gestureRecognizer{
    return NO; //YES：允许右滑返回  NO：禁止右滑返回
}

- (void)goBack
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (void)setRealNameString:(NSString *)realNameString
{
    _realNameString = realNameString;
}

- (IBAction)doneBtnClick:(UIButton *)sender
{
    DLog(@"完成");
    [TalkingData trackEvent:ZGLBankCardInfoAuthenBtnEventID];
    
    NSString *bankCard = self.bankCardTF.text;
    NSString *location = _bankLocation.text;
    NSString *type = _bankTF.text;
//    NSString *bank = [PublicMethod getBankName:bankCard];
    BOOL isBankCard = [PublicMethod isBankCard:bankCard];
    if (isBankCard) {
        
        NSString *Bank = _bankTF.text;
        if (Bank.length>1) {
            
            if (location.length>1) {
                //菊花
                [EasyLoadingView showLoadingText:@"" config:^EasyLoadingConfig *{
                    
                    return [EasyLoadingConfig shared].setLoadingType(LoadingShowTypeIndicator);
                }];
                
                DLog(@"发送验证请求");
                WS(weakself)
                [sZGLHTTPRequestManager BankCardBindingWithNum:bankCard Location:location bankType:type Success:^(id responsedata) {
                    
                    NSString *code = responsedata[@"code"];
                    DLog(@"绑定成功");
                    if ([code integerValue]==1) {
                        [EasyLoadingView hidenLoading];
                        [EasyTextView showSuccessText:@"绑定成功"];
                        
                        //提现
                        ZGLExtractCashController *extractVc = [[ZGLExtractCashController alloc]init];
                        extractVc.isSlide = NO;
                        extractVc.bankCardNumString = [PublicMethod bankCardToAsterisk:bankCard];
                        [weakSelf.navigationController pushViewController:extractVc animated:YES];
                        
                    }else{
                        [EasyLoadingView hidenLoading];
                        [EasyTextView showSuccessText:@"银行卡已绑定"];
                    }
                    
                } Fail:^(ZGLRespondStatusCode bef_status, NSString *bef_message, NSError *error) {
                    
                    DLog(@"绑定失败");
                    [EasyLoadingView hidenLoading];
                    [EasyTextView showErrorText:@"绑定失败,请重试"];
                }];
                
            }else{
                
                [EasyTextView showInfoText:@"请输入所在地"];
            }
        }else{
            
            [EasyTextView showInfoText:@"请输入开户行"];
        }
    }else{
        
        [EasyTextView showInfoText:@"请输入正确银行卡号"];
    }
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
